package  
{
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import Level.Fase;
	import Objetos.Heroi;
	import Objetos.Menu;
	/**
	 * ...
	 * @author Vitor S. Picchi
	 */
	public class Main extends MovieClip
	{
		 
		public var MC_heroi            :Heroi;
		public var MC_tela             :MovieClip;
		private var LV_fase            :Fase;
		private var LevelState         :String;
		public var MC_play             :Menu;
		public var BO_morreu           :Boolean; 
		
		
		
	
	    private static var _instance :Main = null;
		  
		public static function getInstance():Main
		{
			return _instance;
		}
		public static function getStage():Stage
		{
			return getInstance().stage;
		}
		
		public function Main() 
		{
			
			/*MC_play = new Menu;
			MC_play.x = 400
			MC_play.y = 300
			addChild(MC_play)
			
			MC_play.addEventListener(MouseEvent.CLICK , comecar ,false, 0 ,true)*/
		
			
			_instance = this;
			
		   iniciar();
		}	
			
			
		public function iniciar():void
		{
			MC_play = new Menu;
			MC_play.x = 400
			MC_play.y = 300
			addChild(MC_play)
			
			MC_play.addEventListener(MouseEvent.CLICK , comecar ,false, 0 ,true)
		}
		
		public function comecar (e:MouseEvent):void
		{
			removeChild(MC_play)
			
			MC_play.removeEventListener(MouseEvent.CLICK , comecar)
			
			iniciarJogo();
			
			
			
		}
		
		
 		public function iniciarJogo():void
		{
			MC_tela = new MovieClip
			addChild(MC_tela);
			
            LevelState = "Fase"     
			LV_fase = new Fase();
			
			desenharTela();
			
			addEventListener(Event.ENTER_FRAME, update , false, 0, true)
		}
		
		
		public function desenharTela():void
		{
			LV_fase.desenharTela();
		}
		public function update(e:Event):void
		{
			LV_fase.update();
			
			if (BO_morreu == true)
			{
				removeChild(MC_tela)
				removeEventListener(Event.ENTER_FRAME, update)
				//addChild(Main.getInstance().MC_play)
				removeChild(Fase.TX_pontos)
				
				Fase.AR_Chaos.length = 0
				Fase.AR_Obstaculos.length = 0
				MC_tela = null
				
				iniciar();
				
				BO_morreu = false
				
			}
		}
		
	}

}
